/*
 * Copyright (C) 2012 Rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.game;

import java.awt.event.KeyEvent;
import java.util.logging.Logger;
import rpg.KListener;
import rpg.entities.EntityHandler;
import rpg.entities.Player;
import rpg.camera.Camera;
import rpg.gfx.Bitmap;
import rpg.maps.Map;
import rpg.maps.MapHandler;

/**
 * rothens.tarhely.biz
 *
 * @author Rothens
 */
public class SingleGame {

    private MapHandler mapsys;
    public Map actual;
    private static SingleGame instance = null;
    private boolean paused = false;
    private Camera camera = null;

    private SingleGame() {
    }
    
    public Bitmap getEffects(){
        return camera.getCinematicOverlay();
    }

    public static synchronized SingleGame getInstance() {
        if (instance == null) {
            instance = new SingleGame();
        }
        return instance;
    }

    public static void newInstance() {
        getInstance().setMapsys(new MapHandler());
        instance.setActual(instance.getMapsys().loadBinaryMap("main"));
        EntityHandler.getInstance().addEntity(instance.actual.getMapName(), Player.getInstance());
        instance.camera = new Camera(Player.getInstance(), instance.actual);
    }

    public void tick() {

//        Events.Tick();
        EntityHandler.getInstance().tick(Player.getInstance().getMap().getMapName());
        camera.update();
        if (paused && KListener.getInstance().isKeyDown2(KeyEvent.VK_P)) {
            setPaused(false);
        }
    }
    private static final Logger LOG = Logger.getLogger(SingleGame.class.getName());

    /**
     * @return the mapsys
     */
    public MapHandler getMapsys() {
        return mapsys;
    }

    /**
     * @param mapsys the mapsys to set
     */
    public void setMapsys(MapHandler mapsys) {
        this.mapsys = mapsys;
    }

    /**
     * @return the actual
     */
    public Map getActual() {
        return actual;
    }

    /**
     * @param actual the actual to set
     */
    public void setActual(Map actual) {
        this.actual = actual;
    }

    public boolean isPaused() {
        return paused;
    }

    public void setPaused(boolean paused) {
        this.paused = paused;
    }

    public void setCamera(Camera camera) {
        this.camera = camera;
    }

    public Camera getCamera() {
        return camera;
    }
}